/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.sciPersonnelInfo.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.modules.sciPersonnelInfo.domain.SciPersonnelInfoMate;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.ModelMateDemandsDto;
import com.fzhucc.modules.sciPersonnelInfo.service.SciPersonnelInfoMateService;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciPersonnelInfoMateQueryCriteria;
import com.fzhucc.modules.sciTechnologyDemand.domain.dto.ListSelectModelDto;
import com.fzhucc.modules.sciTechnologyDemand.domain.dto.ListSelectModelDto2;
import com.fzhucc.modules.sciTechnologyDemand.domain.dto.MateDto;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2024-01-08
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "劳模:企业工匠匹配需求记录表")
@RequestMapping("/api/sciPersonnelInfoMate")
public class SciPersonnelInfoMateController {

    private final SciPersonnelInfoMateService sciPersonnelInfoMateService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sciPersonnelInfoMate:list')")
    public void exportSciPersonnelInfoMate(HttpServletResponse response, SciPersonnelInfoMateQueryCriteria criteria) throws IOException {
        sciPersonnelInfoMateService.download(sciPersonnelInfoMateService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询企业工匠匹配需求记录表")
    @ApiOperation("查询企业工匠匹配需求记录表")
    //@PreAuthorize("@el.check('sciPersonnelInfoMate:list')")
    public ResponseEntity<Object> querySciPersonnelInfoMate(SciPersonnelInfoMateQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(sciPersonnelInfoMateService.queryAll(criteria,pageable), HttpStatus.OK);
    }

    @PostMapping
    @Log("新增企业工匠匹配需求记录表")
    @ApiOperation("新增企业工匠匹配需求记录表")
    //@PreAuthorize("@el.check('sciPersonnelInfoMate:add')")
    public ResponseEntity<Object> createSciPersonnelInfoMate(@Validated @RequestBody SciPersonnelInfoMate resources){
        return new ResponseEntity<>(sciPersonnelInfoMateService.create(resources), HttpStatus.CREATED);
    }

    @DeleteMapping
    @Log("删除企业工匠匹配需求记录表")
    @ApiOperation("删除企业工匠匹配需求记录表")
    //@PreAuthorize("@el.check('sciPersonnelInfoMate:del')")
    public ResponseEntity<Object> deleteSciPersonnelInfoMate(@RequestBody Integer[] ids) {
        sciPersonnelInfoMateService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping(value = "/getAllMateSciDemandsInfo")
    @Log("查询可分配的所有需求")
    @ApiOperation("查询可分配的所有需求")
    public ResponseEntity<Object> getAllMateSciDemandsInfo(@RequestParam String name){
        return new ResponseEntity<>(sciPersonnelInfoMateService.getAllMateSciDemandsInfo(name), HttpStatus.OK);
    }

    @GetMapping(value = "/mate")
    @Log("劳模匹配需求")
    @ApiOperation("劳模匹配需求")
    public ResponseEntity<Object> mate(SciPersonnelInfoMateQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(sciPersonnelInfoMateService.mateWithMateSort(criteria , pageable), HttpStatus.CREATED);
    }


    @PostMapping(value = "/select")
    @Log("选中匹配到的劳模")
    @ApiOperation("选中匹配到的劳模")
    public ResponseEntity<Object> select(@Validated @RequestBody ListSelectModelDto2 resources) {
        sciPersonnelInfoMateService.select(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PostMapping(value = "/cancelSelect")
    @Log("取消选中匹配到的劳模")
    @ApiOperation("取消选中匹配到的劳模")
    public ResponseEntity<Object> cancelSelect(@Validated @RequestBody ListSelectModelDto2 resources) {
        sciPersonnelInfoMateService.cancelSelect(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
}